package cn.chencaiju.web;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.chencaiju.domain.Post;
import cn.chencaiju.service.PostService;

@Controller
@RequestMapping("/post/")
public class RestPostController {
	@Autowired
	PostService service;
	
	@RequestMapping(path="/{id}",method=RequestMethod.GET)
	@ResponseBody
	public Post getPost(@PathVariable("id") int id) {
		System.out.println(id);
		System.out.println(service.loadPost().size());
		return service.loadPost().get(0);
	}
	@RequestMapping(path="/{id}",method=RequestMethod.DELETE)
	@ResponseBody
	public Post delPost(@PathVariable("id") int id) {
		return service.loadPost().get(0);
	}
	@RequestMapping(path="/rest/load")
	@ResponseBody
	public List<Post> load(){
		return service.loadPost();
	}
}
